Skip to content

fix: pass branch/tag to git clone so --single-branch fetches correct ref#575

Open
yoonsoo-park wants to merge 1 commit into
coderamp-labs:mainfrom
yoonsoo-park:fix/branch-clone-flag
Open

fix: pass branch/tag to git clone so --single-branch fetches correct ref#575
yoonsoo-park wants to merge 1 commit into
coderamp-labs:mainfrom
yoonsoo-park:fix/branch-clone-flag

Conversation

@yoonsoo-park
Copy link
Copy Markdown

Summary

  • --single-branch without -b <branch> only fetches the default branch
  • The subsequent fetch --depth=1 origin <sha> silently fails to retrieve commits from other branches
  • The checkout then uses the default branch content instead of the requested branch

This adds -b <branch> (or -b <tag>) to all three clone code paths:

  1. Partial clone (git.Git().clone() with --filter=blob:none --sparse)
  2. Authenticated GitHub clone (git.Git().clone() with auth URL)
  3. Standard clone (git.Repo.clone_from() via branch kwarg)

Reproduction

gitingest -b my-feature-branch -t "$GITHUB_TOKEN" -o output.txt https://github.com/org/repo

The output contains the default branch's files, not my-feature-branch's files. Verified with 4 different branches on a private repo — all produced byte-identical output matching the default branch.

Root Cause

In src/gitingest/clone.py, resolve_commit() correctly resolves the branch's HEAD SHA via git ls-remote. However, the clone uses --single-branch without specifying which branch, so only the default branch is fetched. The subsequent fetch --depth=1 origin <sha> cannot retrieve commits from unfetched branches in a shallow single-branch clone.

Changes

  • src/gitingest/clone.py: Add -b flag with config.branch or config.tag to all clone paths
  • tests/test_clone.py: Add two tests verifying branch is forwarded to clone commands

Fixes #574

Without `-b <branch>`, `--single-branch` only fetches the default
branch. The subsequent `fetch --depth=1 origin <sha>` silently fails
to retrieve commits from other branches, causing the checkout to use
the default branch content instead.

Adds `-b` flag to all three clone paths (partial, authenticated, and
standard GitPython). Adds two unit tests verifying the branch is
forwarded.

Fixes coderamp-labs#574
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(bug): -b/--branch flag clones default branch instead of specified branch

1 participant